package util

import (
	"fmt"
	"time"
)

func TestTime() {
	now := time.Now()
	fmt.Println(now.String())
	fmt.Println(now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second(), now.Nanosecond())

	fmt.Println(now.Date())
	fmt.Println(now.Clock())

	fmt.Println(now.Unix())
	fmt.Println(now.UnixNano())

	var timestamp = now.UnixNano()
	now2 := time.Unix(0, timestamp)
	fmt.Println(now2)

	now2 = time.Unix(now.Unix(), 0)
	fmt.Println(now2)

	var d time.Duration
	d = time.Millisecond * 1000

	now2 = now2.Add(d)
	fmt.Println(now2)
	d = now2.Sub(now)
	fmt.Println(d)

	fmt.Println(now.Before(now2))
	fmt.Println(now.After(now2))
	fmt.Println(now.Equal(now2))

	timestr := now.Format("2006-01-02 03:04")
	fmt.Println(timestr)

	time3, _ := time.Parse("2006-01-02 15:04:05", "2020-09-15 03:11:19")
	fmt.Println(time3)

	loc, _ := time.LoadLocation("Asia/Shanghai")
	time3, _ = time.ParseInLocation("2006-01-02 15:04:05", "2020-09-15 23:11:19", loc)

	fmt.Println(time3)
}
